<?php
if (!defined('BASEPATH')) {
	exit('No direct script access allowed');
}

class Contact extends CI_Controller {

	function __construct() {
		parent::__construct();
		$this->load->library('parser');
		$this->load->model('m_email');
	}

	function index() {
		$this->parser->set_title('Contact');
		$this->parser->set_desc('Silakan kontak kami');

		$this->parser->theme('front','contact/index');
	}
	
	function send_mail($subject,$email,$pesan,$nama,$from){
		
		$config['protocol'] = 'mail';
        $config['smtp_host'] = 'mail.pilarteknotama.com';
        $config['smtp_port'] = 25;
        $config['smtp_user'] = 'kontak@pilarteknotama.com';
        $config['smtp_pass'] = 'info131089';
		$config['mailtype'] = 'text';
		$str_pesan='Pesan dari '.$nama.' email : ('.$from.')<br>'.$pesan;
 
     
        $this->load->library('email', $config);
		$this->email->clear();
        $this->email->set_newline("\r\n");
         
        $this->email->from('kontak@pilarteknotama.com', 'pilarteknotama.com');
        $this->email->to($email);  
		$this->email->subject($subject);       
        $this->email->message($str_pesan);
         
         
        if($this->email->send()){
            return true;
        }else{
            return show_error($this->email->print_debugger());
        }
	}
	
	function save(){
		$pesan=$this->input->post('pesan');
		$subject=$this->input->post('subject');
		$email=$this->input->post('email');
		$nama=$this->input->post('nama');
		$list_mail=$this->m_email->getAll();
		if(!empty($list_mail)){
			foreach($list_mail as $val){
				$send=$this->send_mail($subject,$val['email'],$pesan,$nama,$email);
			}
		}
		redirect('contact');
	}
}